package com.suypower.carManage.action;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

import javax.servlet.ServletException;

public class MaintainAction extends ActionSupport {

    private String id;
    private String car_code;
    private String maintain_date;
    private String mileage;
    private String name;
    private String remark;
    private String maintain_area;
    private String price;

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getCar_code() {
        return car_code;
    }

    public void setCar_code(String carCode) {
        car_code = carCode;
    }

    public String getMaintain_date() {
        return maintain_date;
    }

    public void setMaintain_date(String maintainDate) {
        maintain_date = maintainDate;
    }

    public String getMileage() {
        return mileage;
    }

    public void setMileage(String mileage) {
        this.mileage = mileage;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMaintain_area() {
        return maintain_area;
    }

    public void setMaintain_area(String maintain_area) {
        this.maintain_area = maintain_area;
    }
    

    public String execute() {
        String res = "";
        DAO dao = new DAO();
        String sql = "";
        if (id != null && !id.equals("")) {
            sql = "UPDATE dbo.tb_maintain SET car_code = '" + car_code
                    + "', maintain_date = '" + maintain_date + "', mileage = '"
                    + mileage + "', name = '" + name + "',price='" + price + "', remark = '" + remark+"',maintain_area='"+maintain_area
                    + "' where id=" + id;
        } else {
            sql = "INSERT INTO tb_maintain(car_code,maintain_date,mileage,name,remark,price,maintain_area)VALUES('"
                    + car_code
                    + "','"
                    + maintain_date
                    + "','"
                    + mileage
                    + "','"
                    + name
                    + "','"
                    + remark
                    + "','"
                    + price
                     + "','"
                    + maintain_area
                    + "')";
        }
        int count = 0;
        try {
            count = dao.execCommand(ConstUtil.DBNAME, sql);
            if (count > 0) {
                res = this.SUCCESS;
            } else {
                res = this.ERROR;
            }
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return res;
    }
}
